<template>
  <el-scrollbar ref="majorScroll">
    <div id="jorLibrary">
      <div class="main">
        <div class="df curpoin nav-box">
          <div class="item-box">全部职业</div>
        </div>
        <majorNav :majorsList="jobList" @handleNavScorll="handleNavScorll" />
        <div style="display: flex">
          <majorsListTable
            :majorsList="jobList"
            :majorType="majorType"
            ref="majorsListTableRef"
            @handleScroll="handleScroll"
            @handleListScroll="handleListScroll"
          />
          <div>
            <div style="margin: 15px 0 0 40px">
              <hotList :hostDataList="hostDataList" type="4" />
            </div>
            <div style="margin: 15px 0 0 40px">
              <hotList :hostDataList="hotCompanyList" type="5" />
            </div>
          </div>
        </div>
      </div>
    </div>
  </el-scrollbar>
</template>

<script setup>
import { ref } from 'vue';
import majorNav from '../majorLibrary/components/MajorNav';
import majorsListTable from '../majorLibrary/components/MajorsList';
import hotList from '@/components/HotList';
import {
  getAllCareer,
  getHotCareer,
  getHotCompany,
} from '@/api/majorLibrary/majorLibrary';
const hotCompanyList = ref({
  title: '热门企业',
  hotList: [],
  imgUrl: '',
  type: 1,
});

const hostDataList = ref({
  title: '热门职业',
  hotList: [],
  imgUrl: '',
});
const jobList = ref([]);
const majorType = ref('3');
const majorsListTableRef = ref('');
const majorScroll = ref(null);
const fetchAllCareer = () => {
  getAllCareer({ deep: 3 }).then((res) => {
    if (res.data.code == 20000) {
      jobList.value = res.data.data;
    }
  });
};
fetchAllCareer();

// 热门职业
const fetchHotCareer = () => {
  getHotCareer().then((res) => {
    if (res.data.code == 20000) {
      hostDataList.value.hotList = res.data.data;
    }
  });
};
fetchHotCareer();

// 热门企业
const fetchHotCompany = () => {
  getHotCompany().then((res) => {
    if (res.data.code == 20000) {
      hotCompanyList.value.hotList = res.data.data;
    }
  });
};
fetchHotCompany();
const handleNavScorll = (index) => {
  majorsListTableRef.value.handleJorLisScroll(index);
};
const handleScroll = (scroll) => {
  majorScroll.value.scrollTo({ top: scroll - 140, behavior: 'smooth' });
};
const handleListScroll = (scroll) => {
  majorScroll.value.scrollTo({ top: scroll - 140, behavior: 'smooth' });
};
</script>

<style lang="scss" scoped>
#jorLibrary {
  margin-top: 20px;
  .nav-box {
    border-bottom: 1px solid var(--color-text);
    .item-box {
      background: var(--color-text);
      color: #fff;
      padding: 10px 30px;
      // border-radius: 4px;
      border-top-left-radius: 4px;
      border-top-right-radius: 4px;
    }
  }
}
</style>
